﻿{extend name="layout/base" /}

{block name="meta"}
{__block__}
<link href="__ADDON__/__STYLE__/css/cart.css" rel="stylesheet">
<link href="__CDN__/assets/libs/bootstrap-table/dist/bootstrap-table.min.css" rel="stylesheet">
<link href="__ADDON__/__STYLE__/js/bt-ext/bt-group-by.css" rel="stylesheet">
{/block}


{block name="body"}
<body class="shopping_cart_page">
{/block}

{block name="main"}

  <!-- Main Container -->
    <div class="container">
      <div id="stepflex" class="stepflex">
        <dl class="first doing">
          <dt class="s-num">1</dt>
          <dd class="s-text">我的购物车</dd>
          <dd></dd>
        </dl>
        <dl class="normal">
          <dt class="s-num1">2</dt>
          <dd class="s-text1">填写核对订单信息</dd>
        </dl>
        <dl class="last">
          <dt class="s-num1">3</dt>
          <dd class="s-text1">成功提交订单</dd>
        </dl>
      </div>
      <div class='mall-clear'></div>
      <div class='main-head'>我的购物车</div>
      <table id="table"
             data-select-item-name="id"
             data-group-by="true"
             data-group-by-field="name"
             data-group-by-sum-field="shoptotal"
             data-group-by-total-field="carttotal">
        <thead>
        <tr>
          <th data-field="goodsimg" data-formatter="imageFormatter" >图片</th>
          <th data-field="goodsname" data-formatter="goodsnameFormatter">名称与规格</th>
          <th data-field="shopprice" data-align="right" data-valign="middle">价格</th>
          <th data-field="num" data-formatter="numFormatter" data-width="100px" data-align="center" data-valign="middle">数量</th>
          <th data-field="total" data-align="right" data-valign="middle" >小计</th>
        </tr>
        </thead>
      </table>

      <div class='cart-btn'>
        <a href='{:addon_url("mall/index/index")}' class='mall-contnue mall-cart-asha'>继续购物</a>
        <a href='#none' onclick='addOrder()' class='mall-next mall-cart-reda'>结算</a>
        <div class='mall-clear'></div>
      </div>
    </div>
   <!-- Footer -->

{/block}

{block name="js"}
{__block__}
<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
<script src="__CDN__/assets/libs/bootstrap-table/dist/bootstrap-table.min.js"></script>
<script src="__CDN__/assets/libs/bootstrap-table/dist/bootstrap-table-locale-all.min.js"></script>
<script src="__ADDON__/__STYLE__/js/bt-ext/bt-group-by.js" ></script>
<script>
    var $table = $('#table');

    function initTable() {
        $table.bootstrapTable({
            locale: require.config.language,
            url: "/addons/mall/cart/indexVisitor",
            uniqueId: "id",
            "groupByFormatter": function (value, row, index) {
                var html = [];
                html.push(value);
                if (row['shopQQ'] != '') {
                    html.push('<a href="tencent://message/?uin=' + row['shopQQ'] + '&Site=QQ交谈&Menu=yes">\n' +
                        '<img border="0" src="https://wpa.qq.com/pa?p=1:' + row['shopQQ'] + ':7" alt="QQ交谈" width="71" height="24" />\n' +
                        '</a>\n');
                }
                if (row['shopWangWang'] != '') {
                    html.push('<a target="_blank" href="https://www.taobao.com/webww/ww.php?ver=3&touid=' + row['shopWangWang'] + '&siteid=cntaobao&status=1&charset=utf-8">\n' +
                        '<img border="0" src="https://amos.alicdn.com/realonline.aw?v=2&uid=' + row['shopWangWang'] + '&site=cntaobao&s=1&charset=utf-8" alt="和我联系" />\n' +
                        '</a>\n');
                }
                return html.join('');
            },
        });

    }

    $(function() {
        initTable()

        $('#locale').change(initTable)

    })

    /**
     * 新建实物订单
     */
    function addOrder(){
        location.href = '/addons/mall/Order/addVisitor?num=' + $(".buy-num").val();
    }

    /**
     * 更改购物车数量
     * @param cart_id
     * @param input
     */
    function change_num(cart_id, input){
        var _value = input.value;
        var url = '/addons/mall/Cart/indexVisitor';
        $.get(url,{'num': _value}, function(ret){
            if(ret.code){
                $table.bootstrapTable('load',ret.data);
            }else{
                layer.msg(ret.msg);
            }
        }, 'json');
    }

</script>
{/block}

